package cn.zwx.zookeeper.config.example.utils;

import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 * @author zhangwenxue
 */
public class ProcessNestMapUtil {

    /**
     * 解决嵌套json问题
     */
    public static void processNestMap(String prefix, Map<String, Object> properties, Map<String,Object> fileMap) throws UnsupportedEncodingException {
        if (prefix != null && prefix.trim().length()>0) {
            prefix += ".";
        }
        for (Map.Entry<String, Object> entrySet : fileMap.entrySet()) {
            if (entrySet.getValue() instanceof Map) {
                // 处理嵌套
                Map<String, Object> valueMap = (Map<String, Object>) entrySet.getValue();
                processNestMap(prefix + entrySet.getKey(), properties, valueMap);
            } else {
                // 解决乱码问题
                properties.put(prefix + entrySet.getKey(), entrySet.getValue());
            }
        }
    }
}
